/**
 * 
 */
package com.csc.bankingsystem.web.spring.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import com.csc.bankingsystem.core.service.HistoryRecordService;
import com.csc.bankingsystem.core.service.TokenRecordService;

/**
 * @author angelkid
 *
 */
public class BSLogoutSuccessHandler implements LogoutSuccessHandler {

	@Autowired
	private HistoryRecordService historyRecordService;
	
	@Override
	public void onLogoutSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		if(authentication != null){
			historyRecordService.saveLogoutSuccessByLoginId((String) authentication.getPrincipal());
		}

	}

}
